package com.client.view;


import javax.swing.JPanel;

import java.awt.Color;
import java.awt.BorderLayout;
import java.awt.Font;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.client.ctrl.RoatCtrl;
import com.entity.Campus;
import com.entity.Class;
import com.entity.Collage;
import com.entity.Department;
import com.entity.Grade;
import com.entity.Major;
import com.util.CommonUtil;
import com.util.MyTable;

public class BasicSetPanel extends JPanel implements ChangeListener {
	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JTabbedPane tabbPane;
	JPanel campusPanel;
	JPanel collagePanel;
	JPanel departmentPanel;
	JPanel majorPanel;
	JPanel gradePanel;
	JPanel classPanel;
	public JScrollPane scrollPane;
	private RoatCtrl roatCtrl=new RoatCtrl();
	/**
	 * Create the panel.
	 */
	public BasicSetPanel(){
		setBackground(new Color(252,251,248));
        setLayout(new BorderLayout(0, 0));
        
        tabbPane = new JTabbedPane(JTabbedPane.LEFT);
        tabbPane.setBackground(new Color(255,255,255));
        tabbPane.setForeground(Color.blue);
        tabbPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        tabbPane.setFont(new Font(null,Font.BOLD,24));
        tabbPane.addChangeListener(this);
        add(tabbPane);
        
		tabbPane.addTab("校区管理", null,null, null);
        
        tabbPane.addTab("学院管理", null, null, null);
        
        tabbPane.addTab("学系管理", null, null, null);
        
        tabbPane.addTab("专业管理", null, null, null);
        
        tabbPane.addTab("年级管理", null, null, null);
        
        tabbPane.addTab("班级管理", null, classPanel, null);
        
	}	
	

	public void stateChanged(ChangeEvent e) {
		if(tabbPane.getSelectedIndex()==0){
			
			campusPanel = new JPanel();
	        campusPanel.setBackground(new Color(200,221,242));
	        campusPanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        campusPanel.add(schoolNameLabel);
	        
	        
            Vector<Vector<Object>> campuses=roatCtrl.tabChange(0,null);
			
			Vector<String> columnsNames=new Vector<String>();
			columnsNames.add("选中");
			columnsNames.add("校区名");
			columnsNames.add("地址");
			columnsNames.add("操作");
			
			
			final MyTable table=new MyTable(campuses,columnsNames,new int[]{100,300,600,100},"校区表");
			final JScrollPane scrollPane = new JScrollPane();
			scrollPane.setViewportView(table);
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45, 80, 1200, 460);
            campusPanel.add(scrollPane);
	        
	        JButton addCampusButton = new JButton("添加");
	        CommonUtil.setFont(addCampusButton, 7);
	        addCampusButton.setBackground(new Color(142,240,146));
	        addCampusButton.setForeground(new Color(64,60,69));
	        addCampusButton.setBounds(500, 560, 100, 30);
	        campusPanel.add(addCampusButton);
	        addCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					new CampusDialog(null).createCampusDialog((JTable)scrollPane.getViewport().getView());
					
				}
			});
	        
	        JButton delCampusButton = new JButton("删除");
	        CommonUtil.setFont(delCampusButton, 7);
	        delCampusButton.setBackground(new Color(209,138,249));
	        delCampusButton.setForeground(new Color(64,60,69));
	        delCampusButton.setBounds(700, 560, 100, 30);
	        delCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					roatCtrl.delcampusCtrl(scrollPane);
					
				}
			});
	        campusPanel.add(delCampusButton);
			
			tabbPane.setComponentAt(0, campusPanel);
            
            scrollPane.setVerticalScrollBarPolicy( 
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
		}else if(tabbPane.getSelectedIndex()==1){
			collagePanel = new JPanel();
	        collagePanel.setBackground(new Color(200,221,242));
	        collagePanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        collagePanel.add(schoolNameLabel);
	        
	        final JScrollPane scrollPane = new JScrollPane();
			
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45,110, 1200, 430);
            scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
            collagePanel.add(scrollPane);
	        
            final Vector<Vector<Object>> campuses=roatCtrl.queryCampuses();
            
            final JComboBox<String> campusBox=new JComboBox<String>();
           CommonUtil.setFont(campusBox,2);
           campusBox.setBackground(new Color(255,255,255));
           campusBox.setForeground(new Color(78,83,87));
           campusBox.addItem("<---请选择校区--->");
	        for(int i=0; i<campuses.size();i++){
	        	campusBox.addItem((String)campuses.get(i).get(1));
	        }
	        campusBox.setBounds(45,70,220,30);
	        campusBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String campusName=campusBox.getSelectedItem().toString();
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						final Vector<Vector<Object>> collageValues=roatCtrl.tabChange(1,campusNo);
		                Vector<String> columnsNames=new Vector<String>();
		    			columnsNames.add("选中");
		    			columnsNames.add("学院名");
		    			columnsNames.add("操作");
		    			
		    			final MyTable table=new MyTable(collageValues,columnsNames,new int[]{100,900,100},"学院表");
		    			scrollPane.setViewportView(table);
					}else{
						scrollPane.setViewportView(null);
					}
				}
			});
			collagePanel.add(campusBox);

          
			
			
	        JButton addCampusButton = new JButton("添加");
	        CommonUtil.setFont(addCampusButton, 7);
	        addCampusButton.setBackground(new Color(142,240,146));
	        addCampusButton.setForeground(new Color(64,60,69));
	        addCampusButton.setBounds(500, 560, 100, 30);
	        collagePanel.add(addCampusButton);
	        addCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String campusName=campusBox.getSelectedItem().toString();
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						new CollageDialog(new Collage(null, null, campusNo)).createCollageDialog((MyTable)scrollPane.getViewport().getView());
					}
				}
			});
	        
	        JButton delCampusButton = new JButton("删除");
	        CommonUtil.setFont(delCampusButton, 7);
	        delCampusButton.setBackground(new Color(209,138,249));
	        delCampusButton.setForeground(new Color(64,60,69));
	        delCampusButton.setBounds(700, 560, 100, 30);
	        delCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String campusName=campusBox.getSelectedItem().toString();
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						roatCtrl.delCollageCtrl(scrollPane,campusNo);
						}
				}
			});
	        collagePanel.add(delCampusButton);
			tabbPane.setComponentAt(1, collagePanel); 
		}else if(tabbPane.getSelectedIndex()==2){
			departmentPanel = new JPanel();
	        departmentPanel.setBackground(new Color(200,221,242));
	        departmentPanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        departmentPanel.add(schoolNameLabel);
	        
	        final JScrollPane scrollPane = new JScrollPane();
			
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45,110, 1200, 430);
            scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
            departmentPanel.add(scrollPane);
	        
            
            final JComboBox<String> campusBox=new JComboBox<String>();
            CommonUtil.setFont(campusBox,2);
            campusBox.setBackground(new Color(255,255,255));
            campusBox.setForeground(new Color(78,83,87));
            campusBox.addItem("<---请选择校区--->");
 	        campusBox.setBounds(50,70,220,30);
 			Vector<Vector<Object>> campuses=roatCtrl.queryCampuses();
            for (Vector<Object> campus:campuses) {
            	campusBox.addItem(campus.get(1).toString());
			}
 	        departmentPanel.add(campusBox);
 	        
 	       final JComboBox<String> collageBox=new JComboBox<String>();
           CommonUtil.setFont(collageBox,2);
           collageBox.setBackground(new Color(255,255,255));
           collageBox.setForeground(new Color(78,83,87));
           collageBox.addItem("<---请选择学院--->");
	       collageBox.setBounds(280,70,220,30);
	       departmentPanel.add(collageBox);
 	        
	        campusBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					DefaultComboBoxModel<String> boxModel1=new DefaultComboBoxModel<String>();
					boxModel1.addElement("<---请选择学院--->");
					String campusName=campusBox.getSelectedItem().toString();
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						Vector<Vector<Object>> collages=roatCtrl.queryCollages(campusNo);
						for(Vector<Object> collage:collages){
							boxModel1.addElement((String) collage.get(1));
						}
					}
				   scrollPane.setViewportView(null);
		            collageBox.setModel(boxModel1);
				}
			});
 	        collageBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String collageName=collageBox.getSelectedItem().toString();
					if(!collageBox.getItemAt(0).equals(collageName)){
						String collageNo=((Collage)roatCtrl.queryCollage(collageName)).getCollageNo();
							final Vector<Vector<Object>> departmentValues=roatCtrl.tabChange(2,collageNo);
			                Vector<String> columnsNames=new Vector<String>();
			    			columnsNames.add("选中");
			    			columnsNames.add("学系");
			    			columnsNames.add("操作");
			    			
			    			MyTable table=new MyTable(departmentValues,columnsNames,new int[]{100,900,100},"学系表");
			    			scrollPane.setViewportView(table);
					}else{
						scrollPane.setViewportView(null);
					}
				}
			});
 	        
			
	        JButton addCampusButton = new JButton("添加");
	        CommonUtil.setFont(addCampusButton, 7);
	        addCampusButton.setBackground(new Color(142,240,146));
	        addCampusButton.setForeground(new Color(64,60,69));
	        addCampusButton.setBounds(500, 560, 100, 30);
	        departmentPanel.add(addCampusButton);
	        addCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String collageName=collageBox.getSelectedItem().toString();
					if(!collageBox.getItemAt(0).equals(collageName)){
						Collage collage=roatCtrl.queryCollage(collageName);
						new DepartmentDialog(new Department(null, collage.getCollageNo(), null)).
						createDepartmentDialog((MyTable)scrollPane.getViewport().getView());
					}
				}
			});
	        
	        JButton delCampusButton = new JButton("删除");
	        CommonUtil.setFont(delCampusButton, 7);
	        delCampusButton.setBackground(new Color(209,138,249));
	        delCampusButton.setForeground(new Color(64,60,69));
	        delCampusButton.setBounds(700, 560, 100, 30);
	        delCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String collageName=collageBox.getSelectedItem().toString();
					if(!collageBox.getItemAt(0).equals(collageName)){
						Collage collage=roatCtrl.queryCollage(collageName);
						roatCtrl.delDepartmentCtrl(scrollPane,collage.getCollageNo());
					}
				}
			});
	        departmentPanel.add(delCampusButton);
			tabbPane.setComponentAt(2, departmentPanel); 
		}else if(tabbPane.getSelectedIndex()==3){
			majorPanel = new JPanel();
	        majorPanel.setBackground(new Color(200,221,242));
	        majorPanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        majorPanel.add(schoolNameLabel);
	        
	        final JScrollPane scrollPane = new JScrollPane();
			
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45,130, 1200, 410);
            scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
            majorPanel.add(scrollPane);
	        
            
            final JComboBox<String> campusBox=new JComboBox<String>();
            CommonUtil.setFont(campusBox,2);
            campusBox.setBackground(new Color(255,255,255));
            campusBox.setForeground(new Color(78,83,87));
            campusBox.addItem("<---请选择校区--->");
 	        campusBox.setBounds(50,90,220,30);
 			Vector<Vector<Object>> campuses=roatCtrl.queryCampuses();
            for (Vector<Object> campus:campuses) {
            	campusBox.addItem(campus.get(1).toString());
			}
 	        majorPanel.add(campusBox);
 	        
 	       final JComboBox<String> collageBox=new JComboBox<String>();
           CommonUtil.setFont(collageBox,2);
           collageBox.setBackground(new Color(255,255,255));
           collageBox.setForeground(new Color(78,83,87));
           collageBox.addItem("<---请选择学院--->");
	       collageBox.setBounds(280,90,220,30);
	       majorPanel.add(collageBox);
	       
	       final JComboBox<String> departmentBox=new JComboBox<String>();
           CommonUtil.setFont(departmentBox,2);
           departmentBox.setBackground(new Color(255,255,255));
           departmentBox.setForeground(new Color(78,83,87));
           departmentBox.addItem("<---请选择学系--->");
	       departmentBox.setBounds(510,90,220,30);
	       majorPanel.add(departmentBox);
 	        
	        campusBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					DefaultComboBoxModel<String> boxModel1=new DefaultComboBoxModel<String>();
					boxModel1.addElement("<---请选择学院--->");
					DefaultComboBoxModel<String> boxModel2=new DefaultComboBoxModel<String>();
					boxModel2.addElement("<---请选择学系--->");
					String campusName=campusBox.getSelectedItem().toString();
					scrollPane.setViewportView(null);
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						Vector<Vector<Object>> collages=roatCtrl.queryCollages(campusNo);
						for(Vector<Object> collage:collages){
							boxModel1.addElement((String) collage.get(1));
						}
					}
					collageBox.setModel(boxModel1);
					departmentBox.setModel(boxModel2);
				}
			});
 	        collageBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					        DefaultComboBoxModel<String> boxModel=new DefaultComboBoxModel<String>();
					        boxModel.addElement("<---请选择学系--->");
					        scrollPane.setViewportView(null);
					        String collageName=collageBox.getSelectedItem().toString();
					        if(!collageBox.getItemAt(0).equals(collageName)){
					        String collageNo=((Collage)roatCtrl.queryCollage(collageName)).getCollageNo();
							final Vector<Vector<Object>> departments=roatCtrl.queryDepartments(collageNo);
							
							for(Vector<Object> department:departments){
								boxModel.addElement((String) department.get(1));
							}
					        }
				            departmentBox.setModel(boxModel);
				}
			});
 	       departmentBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String deptName= departmentBox.getSelectedItem().toString();
					if(!departmentBox.getItemAt(0).equals(deptName)){
						String deptNo=((Department)roatCtrl.queryDepartment(deptName)).getDeptNo();
						final Vector<Vector<Object>> majors=roatCtrl.tabChange(3, deptNo);
				                Vector<String> columnsNames=new Vector<String>();
				    			columnsNames.add("选中");
				    			columnsNames.add("专业");
				    			columnsNames.add("操作");
				    			
				    			MyTable table=new MyTable(majors,columnsNames,new int[]{100,900,100},"专业表");
				    			scrollPane.setViewportView(table);
					}else{
						scrollPane.setViewportView(null);
					}
				}
			});
			
	        JButton addCampusButton = new JButton("添加");
	        CommonUtil.setFont(addCampusButton, 7);
	        addCampusButton.setBackground(new Color(142,240,146));
	        addCampusButton.setForeground(new Color(64,60,69));
	        addCampusButton.setBounds(500, 560, 100, 30);
	        majorPanel.add(addCampusButton);
	        addCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String departmentName=departmentBox.getSelectedItem().toString();
					if(!departmentBox.getItemAt(0).equals(departmentName)){
						Department department=roatCtrl.queryDepartment(departmentName);
						new MajorDialog(new Major(null, null, department.getDeptNo())).createMajorDialog((MyTable)scrollPane.getViewport().getView());
					}
				}
			});
	        
	        JButton delCampusButton = new JButton("删除");
	        CommonUtil.setFont(delCampusButton, 7);
	        delCampusButton.setBackground(new Color(209,138,249));
	        delCampusButton.setForeground(new Color(64,60,69));
	        delCampusButton.setBounds(700, 560, 100, 30);
	        delCampusButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String departmentName=departmentBox.getSelectedItem().toString();
					if(!departmentBox.getItemAt(0).equals(departmentName)){
						Department department=roatCtrl.queryDepartment(departmentName);
						roatCtrl.delMajorCtrl(scrollPane,department.getDeptNo());
					}
				}
			});
	        majorPanel.add(delCampusButton);
			tabbPane.setComponentAt(3, majorPanel); 
		}else if(tabbPane.getSelectedIndex()==4){
			
			gradePanel = new JPanel();
	        gradePanel.setBackground(new Color(200,221,242));
	        gradePanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        gradePanel.add(schoolNameLabel);
	        
	        
            Vector<Vector<Object>> grades=roatCtrl.tabChange(4, null);
			
			Vector<String> columnsNames=new Vector<String>();
			columnsNames.add("选中");
			columnsNames.add("年级");
			columnsNames.add("操作");
			
			
		    final MyTable table=new MyTable(grades,columnsNames,new int[]{100,900,100},"年级表");
			final JScrollPane scrollPane = new JScrollPane();
			scrollPane.setViewportView(table);
			scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45, 80, 1200, 460);
            gradePanel.add(scrollPane);
	        
	        JButton addGradeButton = new JButton("添加");
	        CommonUtil.setFont(addGradeButton, 7);
	        addGradeButton.setBackground(new Color(142,240,146));
	        addGradeButton.setForeground(new Color(64,60,69));
	        addGradeButton.setBounds(500, 560, 100, 30);
	        gradePanel.add(addGradeButton);
	        addGradeButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					new GradeDialog(null).createGradeDialog((MyTable)scrollPane.getViewport().getView());
				}
			});
	        
	        JButton delgradeButton = new JButton("删除");
	        CommonUtil.setFont(delgradeButton, 7);
	        delgradeButton.setBackground(new Color(209,138,249));
	        delgradeButton.setForeground(new Color(64,60,69));
	        delgradeButton.setBounds(700, 560, 100, 30);
	        delgradeButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					roatCtrl.delGradeCtrl(scrollPane);
					
				}
			});
	        gradePanel.add(delgradeButton);
			tabbPane.setComponentAt(4, gradePanel);
		}else if(tabbPane.getSelectedIndex()==5){
			classPanel = new JPanel();
	        classPanel.setBackground(new Color(200,221,242));
	        classPanel.setLayout(null);
	        
	        JLabel schoolNameLabel = new JLabel("中信大学");
			CommonUtil.setFont(schoolNameLabel, 4);
	        schoolNameLabel.setBounds(550, 30, 240, 40);
	        classPanel.add(schoolNameLabel);
	        
	        final JScrollPane scrollPane = new JScrollPane();
			
			scrollPane.getViewport().setBackground(new Color(252,251,248));
            scrollPane.setBounds(45,130, 1200, 410);
            scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
            classPanel.add(scrollPane);
	        
            
            final JComboBox<String> campusBox=new JComboBox<String>();
            CommonUtil.setFont(campusBox,2);
            campusBox.setBackground(new Color(255,255,255));
            campusBox.setForeground(new Color(78,83,87));
            campusBox.addItem("<---请选择校区--->");
 	        campusBox.setBounds(50,90,220,30);
 			Vector<Vector<Object>> campuses=roatCtrl.queryCampuses();
            for (Vector<Object> campus:campuses) {
            	campusBox.addItem(campus.get(1).toString());
			}
 	        classPanel.add(campusBox);
 	        
 	       final JComboBox<String> collageBox=new JComboBox<String>();
           CommonUtil.setFont(collageBox,2);
           collageBox.setBackground(new Color(255,255,255));
           collageBox.setForeground(new Color(78,83,87));
           collageBox.addItem("<---请选择学院--->");
	       collageBox.setBounds(280,90,220,30);
	       classPanel.add(collageBox);
	       
	       final JComboBox<String> departmentBox=new JComboBox<String>();
           CommonUtil.setFont(departmentBox,2);
           departmentBox.setBackground(new Color(255,255,255));
           departmentBox.setForeground(new Color(78,83,87));
           departmentBox.addItem("<---请选择学系--->");
	       departmentBox.setBounds(510,90,220,30);
	       classPanel.add(departmentBox);
	       
	       final JComboBox<String> majorBox=new JComboBox<String>();
           CommonUtil.setFont(majorBox,2);
           majorBox.setBackground(new Color(255,255,255));
           majorBox.setForeground(new Color(78,83,87));
           majorBox.addItem("<---请选择专业--->");
	       majorBox.setBounds(740,90,220,30);
	       classPanel.add(majorBox);
 	        
	       final JComboBox<String> gradeBox=new JComboBox<String>();
           CommonUtil.setFont(gradeBox,2);
           gradeBox.setBackground(new Color(255,255,255));
           gradeBox.setForeground(new Color(78,83,87));
           gradeBox.addItem("<---请选择年级--->");
	       gradeBox.setBounds(970,90,220,30);
	       classPanel.add(gradeBox);
	       
	        campusBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					DefaultComboBoxModel<String> boxModel1=new DefaultComboBoxModel<String>();
					boxModel1.addElement("<---请选择学院--->");
					DefaultComboBoxModel<String> boxModel2=new DefaultComboBoxModel<String>();
					boxModel2.addElement("<---请选择学系--->");
					String campusName=campusBox.getSelectedItem().toString();
					scrollPane.setViewportView(null);
					if(!campusBox.getItemAt(0).equals(campusName)){
						String campusNo=((Campus)roatCtrl.queryCampus(campusName)).getCampusno();
						Vector<Vector<Object>> collages=roatCtrl.queryCollages(campusNo);
						for(Vector<Object> collage:collages){
							boxModel1.addElement((String) collage.get(1));
						}
					}
					collageBox.setModel(boxModel1);
					departmentBox.setModel(boxModel2);
				}
			});
 	        collageBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					        DefaultComboBoxModel<String> boxModel=new DefaultComboBoxModel<String>();
					        boxModel.addElement("<---请选择学系--->");
					        scrollPane.setViewportView(null);
					        String collageName=collageBox.getSelectedItem().toString();
					        if(!collageBox.getItemAt(0).equals(collageName)){
					        String collageNo=((Collage)roatCtrl.queryCollage(collageName)).getCollageNo();
							final Vector<Vector<Object>> departments=roatCtrl.queryDepartments(collageNo);
							
							for(Vector<Object> department:departments){
								boxModel.addElement((String) department.get(1));
							}
					        }
				            departmentBox.setModel(boxModel);
				}
			});
 	       departmentBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
			        DefaultComboBoxModel<String> boxModel=new DefaultComboBoxModel<String>();
			        boxModel.addElement("<---请选择专业--->");
					String deptName= departmentBox.getSelectedItem().toString();
					if(!departmentBox.getItemAt(0).equals(deptName)){
						String deptNo=((Department)roatCtrl.queryDepartment(deptName)).getDeptNo();
						final Vector<Vector<Object>> majors=roatCtrl.tabChange(3,deptNo);
						for(Vector<Object> major:majors){
							boxModel.addElement((String) major.get(1));
						}
					}
					majorBox.setModel(boxModel);
					scrollPane.setViewportView(null);
				}
			});
 	      majorBox.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					DefaultComboBoxModel<String> boxModel=new DefaultComboBoxModel<String>();
			        boxModel.addElement("<---请选择年级--->");
					String majorName= majorBox.getSelectedItem().toString();
					if(!majorBox.getItemAt(0).equals(majorName)){
						final Vector<Vector<Object>> grades=roatCtrl.tabChange(4,null);
						for(Vector<Object> grade:grades){
							boxModel.addElement((String) grade.get(1));
						}
					}
					gradeBox.setModel(boxModel);
					scrollPane.setViewportView(null);
				}
			});
 	           
 	      gradeBox.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String gradeName= gradeBox.getSelectedItem().toString();
					String majorName= majorBox.getSelectedItem().toString();
					if(!gradeBox.getItemAt(0).equals(gradeName)&&!majorBox.getItemAt(0).equals(majorName)){
						String majorNo=((Major)roatCtrl.queryMajor(majorName)).getMajorNo();
						String gradeNo=((Grade)roatCtrl.queryGrade(gradeName)).getGradeNo();
						final Vector<Vector<Object>> classes=roatCtrl.tabChange(5,majorNo+","+gradeNo);
							Vector<String> columnNames=new Vector<String>();
							columnNames.add("选中");
							columnNames.add("班级");
							columnNames.add("操作");
							MyTable table=new MyTable(classes, columnNames, new int[]{100,900,200},"班级表");
							scrollPane.setViewportView(table);
						
					}
				}
			});
 	       
 	       
	        JButton addCampusButton = new JButton("添加");
	        CommonUtil.setFont(addCampusButton, 7);
	        addCampusButton.setBackground(new Color(142,240,146));
	        addCampusButton.setForeground(new Color(64,60,69));
	        addCampusButton.setBounds(500, 560, 100, 30);
	        classPanel.add(addCampusButton);
	        addCampusButton.addActionListener(new ActionListener() {
				
				public void actionPerformed(ActionEvent e) {
					String gradeName= gradeBox.getSelectedItem().toString();
					String majorName= majorBox.getSelectedItem().toString();
					if(!gradeBox.getItemAt(0).equals(gradeName)&&!majorBox.getItemAt(0).equals(majorName)){
						String majorNo=((Major)roatCtrl.queryMajor(majorName)).getMajorNo();
						String gradeNo=((Grade)roatCtrl.queryGrade(gradeName)).getGradeNo();
					    new ClassDialog(new Class(null, null, majorNo,gradeNo)).createClassDialog((MyTable)scrollPane.getViewport().getView());
					}
				}
			});
	        
	        JButton delCampusButton = new JButton("删除");
	        CommonUtil.setFont(delCampusButton, 7);
	        delCampusButton.setBackground(new Color(209,138,249));
	        delCampusButton.setForeground(new Color(64,60,69));
	        delCampusButton.setBounds(700, 560, 100, 30);
	        delCampusButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					String gradeName= gradeBox.getSelectedItem().toString();
					String majorName= majorBox.getSelectedItem().toString();
					if(!gradeBox.getItemAt(0).equals(gradeName)&&!majorBox.getItemAt(0).equals(majorName)){
						String majorNo=((Major)roatCtrl.queryMajor(majorName)).getMajorNo();
						String gradeNo=((Grade)roatCtrl.queryGrade(gradeName)).getGradeNo();
					    roatCtrl.delClass(scrollPane,majorNo+","+gradeNo);
					}
				}
			});
	        classPanel.add(delCampusButton);
			tabbPane.setComponentAt(5, classPanel); 
		}
	}
	
}
